function validator(target, validator) {
  return new Proxy(target, {
    _validator: validator,
    set(target, key, value, proxy) {
      console.log(proxy);
      if (target.hasOwnProperty(key)) {
        let va = this._validator[key]
        if (!!va(value)) {
          return Reflect.set(target, key, value, proxy)
        } else {
          throw Error(`${key}不能赋值为${value}`)
        }
      } else {
        throw Error(`${key}不存在`)
      }
    }
  })
}

const personValidators = {
  name(val) {
    return typeof val === "string"
  },
  age(val) {
    return typeof val === "number" && val >= 18
  }
}

class Person {
  constructor(name, age) {
    this.name = name
    this.age = age
    // return validator(this, personValidators)
  }
}
class Man extends Person {
  constructor(name,age,mobi) {
    super(name,age)
    this.mobi = mobi
  }
}

let man = new Man('xx',19,'123')
man.age = 19
man.name = 123
man.mobi = 19;
console.log(man)

function loadImg(src) {
  return new Promise((resolve,reject) => {
    let img = document.createElement('img')
    img.src = src
    img.onload = function () {
      resolve(img)
    }
    img.onerror = function () {
      reject(img)
    }
  })
}

function showImgs(imgs) {
  imgs.forEach((item)=>{
    document.body.appendChild(item)
  })
}

Promise.all([
  loadImg('http://tf2018-admin.jeemoo.com//uploads/tempimages/15345434294776.jpg'),
  loadImg('http://tf2018-admin.jeemoo.com//uploads/tempimages/15347394731806.jpg'),
  loadImg('http://tf2018-admin.jeemoo.com//uploads/tempimages/15347394121989.jpg'),
  loadImg('http://tf2018-admin.jeemoo.com//uploads/tempimages/15344116765365.png'),
  loadImg('http://tf2018-admin.jeemoo.com//uploads/tempimages/15345307125611.jpg')
]).then(showImgs);

{
  let draw = function (count) {
    // 抽奖逻辑
    console.log(`剩余抽奖次数为：${count}`)
  }
  let residue = function* (count) {
    while(count > 0) {
      count--
      yield draw(count)
    }
  }
  let start = residue(5)
  let btn = document.createElement('button')
  btn.id = "btn"
  btn.textContent = "抽奖"
  document.body.appendChild(btn)
  document.getElementById('btn').addEventListener('click',function() {
    start.next()
  })
}

{
  let ajax = function* () {
    yield new Promise((resolve, reject)=>{
      setTimeout(()=>{
        resolve({code:0})
      },1800)
    })
  }
  let pull = function () {
    let genertaor = ajax()
    let step = genertaor.next()
    step.value.then((d)=>{
      if(d.code !== 0) {
        setTimeout(()=>{
          console.log('wait')
          pull()
        },1000)
      }else{
        console.log(d)
      }
    })
  }
}